package com.gzy.cbrsystem.insomnia.action;




import java.util.List;

import com.gzy.cbrsystem.core.ReasoningResult;
import com.gzy.cbrsystem.core.insomnia.InsomniaCaseDescription;
import com.gzy.cbrsystem.core.insomnia.InsomniaReasoner;
import com.gzy.cbrsystem.core.interfaces.CaseBasic;
import com.gzy.cbrsystem.insomnia.ClinicalBit;
import com.gzy.cbrsystem.insomnia.ClinicalBitDAO;
import com.opensymphony.xwork2.ActionSupport;

public class Reasoning extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String caseId;

	protected InsomniaReasoner insomniaReasoner;
	
	protected ClinicalBitDAO clinicalBitDAO;
	protected List<ReasoningResult> reResults;
	
	public List<ReasoningResult> getReResults() {
		return reResults;
	}

	public void setReResults(List<ReasoningResult> reResults) {
		this.reResults = reResults;
	}

	public String getCaseId() {
		return caseId;
	}

	public void setCaseId(String caseId) {
		this.caseId = caseId;
	}
	
	public ClinicalBitDAO getClinicalBitDAO() {
		return clinicalBitDAO;
	}



	public void setClinicalBitDAO(ClinicalBitDAO clinicalBitDAO) {
		this.clinicalBitDAO = clinicalBitDAO;
	}



	public InsomniaReasoner getInsomniaReasoner() {
		return insomniaReasoner;
	}



	public void setInsomniaReasoner(InsomniaReasoner insomniaReasoner) {
		this.insomniaReasoner = insomniaReasoner;
	}



	public String execute() throws Exception {
		ClinicalBit cb=this.clinicalBitDAO.findById(this.caseId);
		CaseBasic query=new InsomniaCaseDescription(cb);
		List<ReasoningResult> reResults=this.insomniaReasoner.reason(query, 20);
//		if(reResults.size()!=1) System.out.println("ERROR");
//		for(ReasoningResult r:reResults)
//		{
//			System.out.println(r.getCase().getCaseIdentifier().get(r.getCase().getCaseDescription()));
//		}
		this.setReResults(reResults);
		return SUCCESS;
	}
}
